var express = require('express');
const userDataModel = require('../model/userDataModel')
const jwt = require('jsonwebtoken')
const VipUerModel = require('../model/vipUserModel')
var router = express.Router();

/* GET users listing. */
router.post('/login', async (req, res, next) => {
    const { mail, password } = req.body
    const data = await userDataModel.findOne({ mail, password })
    if (!data) return res.json({ code: '404', msg: '账号或密码错误' })
    //创建token
    const token = jwt.sign(
        { mail },
        'cbb',
        { expiresIn: 60 * 60 * 24 }
    )
    //发送token跟账号id
    res.json({ code: '200', msg: '登录成功', data: { token: token, mailId: data._id } })
});

router.get('/', async (req, res, next) => {
    const data = await VipUerModel.find()
    res.json({code:"200",data})
});



module.exports = router;
